package com.ophiux.cs.domain.chat.model.entity;

import java.util.ArrayList;
import java.util.List;

import com.ophiux.compoments.TableEnum;
import com.ophiux.cs.domain.chat.exception.MessageSendRecordNotFoundException;
import com.ophiux.cs.domain.core.TbableUniqueIDFactory;
import com.ophiux.utils.common.DateUtil;
import com.ophiux.utils.common.StringUtil;
import com.ophiux.utils.exception.OphiuxParamException;

/**
 * 聊天会话
 * @author chenh
 *cs_chat_session
 */
public class CSChatSession {

	private final static String STATE_VALID = "1";
	private final static String STATE_INVALID = "0";
	
	private final static String SESSION_TYPE_SL = "0";
	private final static String SESSION_TYPE_QL = "0";
	
	private String ID;	//会话ID
	
	private String SESSIION_ID;	//会话标识
	
	private String TARGET_ACC;	//谁的聊天会话，拥有者
	
	private String WHO;	//和谁的聊天会话
	
	private String SESSION_TYPE;	//会话类型   1：私聊   2：群聊
	
	private String STATE;	//状态   1：有效   0：删除
	
	private String CREATE_TIME;	//创建时间
	
	private String RECENT_TIME;	//最近操作时间

	private CSChatMessageSend curChatSend;	//当前聊天记录
	
	
	public CSChatSession() {
		super();
	}

	/**
	 * 创建会话
	 * @param tARGET_ACC	谁的？
	 * @param wHO	和谁的？
	 */
	public CSChatSession(String tARGET_ACC, String wHO) {
		super();
		TARGET_ACC = tARGET_ACC;
		WHO = wHO;
		
		this.ID = TbableUniqueIDFactory.getInstance()
				.createUniqueID(TableEnum.TABLE_SQE_CS_ChAT_SESSION.toString());
		this.SESSIION_ID = this.ID;
		
		this.setSESSION_TYPE(SESSION_TYPE_SL);
		
		this.STATE = STATE_VALID;
		this.setCREATE_TIME(DateUtil.getCurDateStr());
		
	}
	
	/**
	 * 消息发送
	 */
	public void send(CSChatMessageInfo message) {
		CSChatMessageSend csms = new CSChatMessageSend(this.getSESSIION_ID(),
				CSChatMessageSend.TYPE_SEND, message.getDIALOG_ID(), message);
		this.setCurChatSend(csms);
	}
	
	/**
	 * 消息接收
	 */
	public void receive(CSChatMessageInfo message) {
		CSChatMessageSend csms = new CSChatMessageSend(this.getSESSIION_ID(),
				CSChatMessageSend.TYPE_RECEIVE, message.getDIALOG_ID(), message);
		this.setCurChatSend(csms);
	}

	public CSChatMessageSend getCurChatSend() {
		return curChatSend;
	}

	public void setCurChatSend(CSChatMessageSend curChatSend) {
		this.curChatSend = curChatSend;
	}

	public String getID() {
		return ID;
	}

	public void setID(String iD) {
		ID = iD;
	}

	public String getSESSIION_ID() {
		return SESSIION_ID;
	}

	public void setSESSIION_ID(String sESSIION_ID) {
		SESSIION_ID = sESSIION_ID;
	}

	public String getTARGET_ACC() {
		return TARGET_ACC;
	}

	public void setTARGET_ACC(String tARGET_ACC) {
		TARGET_ACC = tARGET_ACC;
	}

	public String getWHO() {
		return WHO;
	}

	public void setWHO(String wHO) {
		WHO = wHO;
	}

	public String getSESSION_TYPE() {
		return SESSION_TYPE;
	}

	public void setSESSION_TYPE(String sESSION_TYPE) {
		SESSION_TYPE = sESSION_TYPE;
	}

	public String getSTATE() {
		return STATE;
	}

	public void setSTATE(String sTATE) {
		STATE = sTATE;
	}

	public String getCREATE_TIME() {
		return CREATE_TIME;
	}

	public void setCREATE_TIME(String cREATE_TIME) {
		CREATE_TIME = cREATE_TIME;
	}

	public String getRECENT_TIME() {
		return RECENT_TIME;
	}

	public void setRECENT_TIME(String rECENT_TIME) {
		RECENT_TIME = rECENT_TIME;
	}

	/**
	 * 删除会话
	 */
	public void removeSession() {
		
		this.setSTATE(STATE_INVALID);
		this.setRECENT_TIME(DateUtil.getCurDateStr());
		
	}
	

	
}
